//
//  WYEditPassWordController.m
//  CirclePush
//
//  Created by admin on 2018/5/22.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYEditPassWordController.h"
#import "UIButton+CountDown.h"
@interface WYEditPassWordController ()
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *top;
@property (strong, nonatomic) IBOutlet UIButton *codeButton;


@property (strong, nonatomic) IBOutlet UILabel *mobileLabel;

@property (strong, nonatomic) IBOutlet UITextField *codeTextfield;
@property (strong, nonatomic) IBOutlet UITextField *password;


@end

@implementation WYEditPassWordController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    // Do any additional setup after loading the view from its nib.
}
-(void)setupUI
{
    [self initTopBarWithTitle:@"修改密码"];
    [self addLeftButton:[UIImage imageNamed:@"return"] width:0 height:0];
    if (kDevice_Is_iPhoneX) {
        self.top.constant = 98;
    }
    self.view.backgroundColor = [UIColor hexStringToColor:@"#f4f4f4" alpha:1.0];
    
    WYUserInfo *info = [WYStoreModule currentUserInfo];
//    self.mobileLabel.text = [NSString stringWithFormat:@"验证码将发送至：%@****%@",[info.telephone substringWithRange:NSMakeRange(0, 2)],[info.telephone substringWithRange:NSMakeRange(6, 4)]];
    self.mobileLabel.text = [NSString stringWithFormat:@"验证码将发送至：%@",[self numberSuitScanf:info.telephone]];

    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)clickSureAction:(id)sender {
    
    if (!self.codeTextfield.text) {
        [self toast:@"请输入验证码"];return;
    }
    if (!self.password.text) {
        [self toast:@"请输入密码"];return;
    }
    
    WEAKSELF
    [WYHttpServer editNumber:nil Withpassword:self.password.text WithCode:self.codeTextfield.text WithHeadImg:nil SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [weakSelf toast:@"修改成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [weakSelf toast:errorMessage];
        }
    }];
}
-  (NSString *)numberSuitScanf:(NSString*)number{
    
    NSMutableString *phoneStr = [NSMutableString stringWithString:number];
    
    NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    // 判断当前字符串是否为手机号
    BOOL isMatch = [pred evaluateWithObject:phoneStr];
    if (isMatch) {
        [phoneStr replaceCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    }
    
    return [NSString stringWithString:phoneStr];
}

- (IBAction)getCodeAction:(id)sender {
    
    [self.codeButton startWithTime:59 title:@"重新获取" countDownTitle:@"s后重新获取" mainColor:[UIColor whiteColor] countColor:[UIColor hexStringToColor:@"#3B80F8" alpha:1.0]];
    WYUserInfo *info = [WYStoreModule currentUserInfo];
    [WYHttpServer sendMessageWithTelephone:info.telephone SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        
        
        
    }];
    
    
}



@end
